package com.DongBing.controller;

import java.util.Arrays;
import java.util.Map;

import com.DongBing.common.utils.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.DongBing.entity.CategoryBrandRelationEntity;
import com.DongBing.service.CategoryBrandRelationService;
import com.DongBing.common.utils.PageUtils;
import com.DongBing.common.utils.R;



/**
 * 品牌分类关联
 *
 * @author ¶­±ù
 * @email 861571118@QQ.com
 * @date 2022-05-16 15:55:04
 */
@RestController
@RequestMapping("/product/categorybrandrelation")
public class CategoryBrandRelationController {

    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = categoryBrandRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);
        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.save(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询这个品牌绑定了多少分类
     * @param brandId 品牌id
     * @return res
     */
    @GetMapping(value = "/findCategoryBrandList/{brandId}")
    public Res<?> findCategoryBrandList(@PathVariable("brandId") String brandId){
        return categoryBrandRelationService.findCategoryBrandList(brandId);
    }

    @PostMapping(value = "/insert")
    public Res<?> CategoryBrandInsert(@RequestBody CategoryBrandRelationEntity bean){
        return categoryBrandRelationService.insert(bean);
    }
}
